home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: ncrgw2.ncr.com!ncrhub6!daynews!falcon!news
- From: Dick Menninger <Dick.Menninger@DaytonOH.ATTGIS.COM>
- Subject: Re: Q: how to handle currency?
- X-Nntp-Posting-Host: 149.25.118.167
- Message-ID: <DM0qBx.CK7@falcon.daytonoh.attgis.com>
- Sender: news@falcon.daytonoh.attgis.com (News administrative Login)
- Reply-To: Dick.Menninger@DaytonOH.ATTGIS.COM (mennid)
- Organization: AT&T Global Information Solutions
- X-Newsreader: DiscussIT 2.5.1.3 for MS Windows [AT&T Software Products Division]
- References: <4e93he$ec@sun.cis.smu.edu>
- Date: Tue, 30 Jan 1996 23:52:45 GMT
-
-
- > ==========Damon Bowman, 1/25/96==========
-
-
- > Another beginner question:
-
- > What data type is used for currency when you want "precision as
- > displayed?" When using the float or double data types, you run into
- > the problem of imprecision. In other words, I want to actually round
- > off my numbers when necessary to create real amounts of EXACTLY 47.23,
- > or whatever the case may be.
- >
- > One of my books suggests that there is a method of doing this with
- > integers, but it does not go into any detail.
-
- > Any assistance is appreciated.
-
- If decimal works for the money, then 64-bit integers will
- do nicely, most likely, since you can get about 20 digits.
- Just have the value represent the smallest amount and
- then divide/mod by the right power of ten to get the parts.
- If you ever need more digits than 20, well they need a
- currency revaluation and they will not be using the right
- side of decimal point. The exception might be some
- economic space game situations (or other games) where
- double precision floating point would work fine for a lot longer.
- You might need to use floating point for calculations
- even if 64-bit integers are fine for actual currency values.
- But if decimal does not work, then it will be trickier
- as there is, probably, a quaint collection of possibilities
- that are not expressed as decimal values.
-
- Good Day
- Dick
- Dick.Menninger@DaytonOH.ATTGIS.COM
-
-